package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    //查看课程大纲计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public ResponseResult<TeachplanVo> treeNodes(@PathVariable("courseId")Long courseId){
        return teachplanService.treeNodes_stream(courseId);
    }

    //新增或修改课程计划
    @PostMapping("/teachplan")
    public ResponseResult<TeachplanVo> saveOrUpdateTeachPlan(@RequestBody TeachplanDto teachplanDto){
        return teachplanService.saveOrUpdateTeachPlan(teachplanDto);
    }

    //删除课程计划
    @DeleteMapping("/teachplan/{id}")
    public ResponseResult deleteTeachPlan(@PathVariable("id")Long teachplanId){
        return teachplanService.deleteTeachPlan(teachplanId);
    }

    //根据id查询课程计划
    @GetMapping("/teachplan/{teachplanId}")
    public ResponseResult<TeachplanVo> findTeachplanById(@PathVariable("teachplanId")Long teachplanId){
        //获取课程计划对象
        Teachplan teachplan = teachplanService.getById(teachplanId);
        //转vo
        TeachplanVo teachplanVo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        //返回
        return ResponseResult.okResult(teachplanVo);
    }
}
